package com.spring.hotel.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spring.hotel.common.JsonResponse;
import com.spring.hotel.entity.PageDTO;
import com.spring.hotel.entity.Room;
import com.spring.hotel.entity.RoomCountDTO;
import com.spring.hotel.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoomService extends ServiceImpl<RoomMapper, Room> {
    @Autowired
    private RoomMapper roomMapper;
    //分页展示
    public JsonResponse pageList(Room room, PageDTO pageDTO) {
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        if (room.getId() != null) {
            queryWrapper.lambda().like(Room::getId, room.getId());
        }
        Page<Room> page = this.page(new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize()), queryWrapper);
        return JsonResponse.success(page);
    }

    //统计信息
    public JsonResponse<RoomCountDTO> getRoomCounts() {
        RoomCountDTO roomCount = new RoomCountDTO();
        roomCount.setRoom(roomMapper.countRooms());
        roomCount.setSingle(roomMapper.countSingleRooms());
        roomCount.setTwin(roomMapper.countTwinRooms());
        roomCount.setLarge(roomMapper.countLargeRooms());
        return JsonResponse.success(roomCount);
    }
}
